package aaa;

public class kuaisu {
	static void swap(int a[], int i, int j){
		
		int temp;
		temp = a[i];
		a[i] = a[j];
		a[j] = temp;
		
	}
	
	
	static int huaFen(int a[], int left, int right){
		int pivot = a[right];
		int tail = left - 1;
		
		for (int i=left; i<right; i++){
			
			if (a[i] <= pivot){
				
				swap(a,++tail,i);
			}
		}
		swap(a, tail+1, right);
		return tail + 1;
		
	}
	
	
	static void quickSort(int a[], int left, int right){
		
		if (left>=right)
			return;
		int pivotIndex = huaFen(a, left, right);
		quickSort(a, left, pivotIndex-1);
		quickSort(a, pivotIndex+1, right);
		}
	

	public static void main(String[] args) {
		int a[] = {15, 1, 2, 5, 23, 15, 1, 2, 5, 27};
		int length = a.length -1 ;
		quickSort(a, 0, length);
		
		for (int i=0; i<length+1; i++){
			System.out.print(" "+a[i]);
		}
		// TODO Auto-generated method stub

	}

}
